package gbsip

import (
	"gitee.com/tonyjia/gb28181/pkg/model"
	constant2 "gitee.com/tonyjia/gb28181/pkg/model/constant"
)

/**
 * @Description 回调上级平台的事件
 * @Author lulili
 * @Date 2024/10/31 14:44
 */

// QueryDeviceInfo 查询平台的设备信息
func QueryDeviceInfo(d model.Device) (model.Device, error) {
	process := c.server.c.Callback[constant2.EVENT_MESSAGE_Query_DeviceInfo]
	device, err := process(d)
	if err != nil {
		return model.Device{}, err
	}
	m := device.(model.Device)
	return m, err
}

// GetCatalogInfo 查询平台的通道信息
func GetCatalogInfo(d model.Device) ([]model.Channel, error) {
	process := c.server.c.Callback[constant2.EVENT_MESSAGE_Query_Catalog]
	channels, err := process(d)
	if err != nil {
		return nil, err
	}
	m := channels.([]model.Channel)
	return m, err
}

// SyncDeviceInfo 向平台传递摄像头信息
func SyncDeviceInfo(device model.Device) error {
	process := c.server.c.Callback[constant2.EVENT_MESSAGE_DeviceInfo]
	_, err := process(device)
	if err != nil {
		return err
	}
	return nil
}

// SyncCatalog 向平台查询通道信息
func SyncCatalog(channels []model.Channel) error {
	process := c.server.c.Callback[constant2.EVENT_MESSAGE_Catalog]
	_, err := process(channels)
	if err != nil {
		return err
	}
	return nil
}

// 将上级平台的媒体信息传递给平台 获取到下级平台的sdp信息
func SyncInvite(sdpInfo model.StreamInfo) (model.StreamInfo, error) {
	process := c.server.c.Callback[constant2.EVENT_INVITE]
	receiveSdpInfo, err := process(sdpInfo)
	if err != nil {
		return model.StreamInfo{}, err
	}
	//解析sdp消息
	receiveSdp := receiveSdpInfo.(model.StreamInfo)
	return receiveSdp, nil
}
